home *** CD-ROM | disk | FTP | other *** search
/ Network Supervisor's Toolkit / Network Supervisor's Toolkit.iso / tools / ubmark / malloc.c < prev    next >
Text File  |  1996-07-10  |  2KB  |  77 lines

  1.  
  2. /*********************************************************
  3. *
  4. *    filename:    malloc.c
  5. *    output file:    malloc
  6. *    programmer:    Michael Day
  7. *    copyright:    Michael Day, 1990; LAN TIMES, 1990
  8. *
  9. *    allocates arrays, fills arrays with characters, copies
  10. *    arrays, frees arrays. Background processes do essentially
  11. *    the same thing in an endless loop. 
  12. *    
  13. *    compile to output files and place executables in /bin
  14. *    
  15. **********************************************************/
  16.  
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <sys/types.h>
  20. #include <prot.h>
  21. #include <string.h>
  22.  
  23. #define  CHARS     1000
  24.  
  25. char        structs[7], proc[7], instr[CHARS];
  26.  
  27. main()    {
  28.     
  29.     int     i, x, r;
  30.     time_t    beg_time, end_time;
  31.     int    cum_time;
  32.     int    *s;
  33.     long    *tloc;
  34.         
  35.     char    *source_array, *temp_array;    
  36.     int    randchar();
  37.     
  38.     printf("Multiprocess memory allocation benchmark\n");
  39.     printf("Copyright 1990 Michael Day and LAN TIMES\n");
  40.     printf("Enter the number of arrays to create for each iteration\n-->");
  41.     scanf("%s", structs);
  42.     printf("Enter the number of background processes to spawn\n-->");
  43.     scanf("%s", proc);
  44.  
  45. /*****     start background processes     *****/
  46.  
  47.     beg_time = time(&tloc);    
  48.     for (i = 0; i < atoi(proc); ++i)    {
  49.         system("/bin/mspawn");    
  50.         printf("%i spawned\n", i+1);
  51.     }
  52.  
  53. /*****     now create static array  and fill it with data     *****/
  54.         
  55.     for(i = 1; i <= 1000; i++)        {
  56.         source_array = (char *)malloc(CHARS + i);    
  57.         memset(source_array, 'a', (sizeof(source_array)));
  58.     
  59. /*****     read and write each record to a temp array, free array    *****/
  60.     
  61.         for(x = 0; x < atoi(structs); x++)    {
  62.             temp_array = (char *)malloc(sizeof(source_array)); 
  63.             memcpy(temp_array, source_array, sizeof(source_array));
  64.             free(temp_array);
  65.         }
  66.     }
  67. /*****     clean up *****/
  68.  
  69.     free(source_array); 
  70.     end_time = time(&tloc);
  71.     cum_time = (end_time - beg_time);
  72.     printf("Elapsed time: %i seconds\n", cum_time);
  73.     printf("Parameters: %s structures\n", structs);
  74.     printf("            %s background processes\n", proc); 
  75.     exit(0);
  76. }
  77.